import React from 'react';
import { Icon } from 'antd';
import {WeaLocaleProvider, WeaTools} from 'ecCom';
import './../../style/loadlog/loadLogs';
import NewLinkeb from '../../public/newlinked/NewLinkeb';
const getLabel = WeaLocaleProvider.getLabel;
export default class loadLogs extends React.Component {
  constructor(props) {
    super(props)
    this.state={
       linked:{
         1:"/spa/hrm/index_mobx.html#/main/hrm/card/cardInfo/",
         2:"/spa/document/index.jsp?id=",
         3:"/workflow/request/ViewRequestForwardSPA.jsp?requestid=",
         4:"/spa/crm/static/index.html#/main/crm/customerView?customerId=",
         5:"/spa/prj/index.html#/main/prj/projectCard?prjid=",
       }
    }
  }
  componentWillMount(){
    WeaTools.callApi('/api/workrelate/common/getRelateURL', 'GET').then((data) => {
      if(data.status){
        let {linked} = this.state;
        linked[4] = data.result[7];
        this.setState({
          linked
        })
      }
    })
  }
  render() {
    const { logsData, lastcount,moretitle,morename} = this.props;
    const {linked} = this.state;
    return (
      <div className={"wea-workrelate-loadLogs " + (this.props.className ? this.props.className : "")}>
        {
          logsData && logsData.length > 0 ? logsData.map((elemnet, index) => {
            return (
              <div className="tabs-comment">
                <span className="comment-name">
                  {elemnet.operatoragent&&<span><a href='javaScript:void(0)' onClick={e => { openhrm(elemnet.operatoragent); window.pointerXY(e) }} title={elemnet.operatoragentname} >{elemnet.operatoragentname}</a>-></span>}
                  <a href='javaScript:void(0)' onClick={e => { openhrm(elemnet.operator); window.pointerXY(e) }} title={elemnet.operatorname} >{elemnet.operatorname}</a>
                </span>
                <span className="comment-time">{elemnet.operatedate}</span>
                <span className="comment-detail" ><span dangerouslySetInnerHTML={{ __html: elemnet.operatetitle }}></span><span className="coment-content" >{elemnet.operatevalue && elemnet.operatevalue.length > 0 ? this.removeHTMLTag(elemnet.operatevalue) : ''}</span>
                  <span className="comment-other" >{elemnet.rlist && elemnet.rlist.length > 0 ? <NewLinkeb ecId={`${this && this.props && this.props.ecId || ''}_NewLinkeb@ceft68@${elemnet.operator}_${index}`} replaceData={elemnet.replaceData} linkurl={linked[elemnet.linktype]} linkdatas={elemnet.rlist} onLinkClick={(id, name, type)=>this.onLinkClick(id, name, type,elemnet.replaceData)}/> : ''}</span>
                </span>
              </div>)
          }) :<span className="comment-tipinfo">{getLabel(84304,"暂无")}</span>
        }
           {lastcount > 0 ? <div className="tabs-comment-more" onClick={()=>this.onMoreClick()} title={moretitle?moretitle:getLabel(82720,"加载更多")}>{morename?morename:getLabel(82720,"加载更多")} <Icon ecId={`${this && this.props && this.props.ecId || ''}_Icon@s5xnk0`} type="down" /></div> : ''}
      </div>
    )
  }
  onMoreClick(id,name,type){
    if(typeof this.props.onMoreClick === "function"){
      this.props.onMoreClick();
    }
  }
  onLinkClick(id, name, type,columninfo){
    if(typeof this.props.onLinkClick === "function"){
      this.props.onLinkClick(id, name, type,columninfo);
    }
  }
  removeHTMLTag(str) {
    str = str.replace(/&nbsp;/ig, "");
    str = str.replace(/<\/?[^>]*>/g, ''); //去除HTML tag
    str = str.replace(/[ | ]*\n/g, '\n'); //去除行尾空白
    //str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
    //str = str.replace(/ /ig, '');//去掉 
    return str;
}

}

